#include <cstdio>
#include <cstring>
using namespace std;

char week[7][5] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
char in[4][85] = {0};

bool isA_G(char c){
    return c <= 'G' && c >= 'A';
}
bool isA_N(char c){
    return c <= 'N' && c >= 'A';
}

bool isNum(char c){
    return c <= '9' && c >= '0';
}

bool isE(char c){
    return c <= 'z' && c >= 'A';
}

int main()
{
    for(int i = 0; i < 4; i++){
        scanf("%s", in[i]);
    }
    bool flag = false;
    for(int i = 0; i <= strlen(in[0]) && i <= strlen(in[1]); i++){
        //相等 且范围在[A - G] 必须先满足这个条件才能进行下个判断
        if(in[0][i] == in[1][i] && isA_G(in[0][i]) && !flag){
            printf("%s ", week[ in[0][i] - 'A' ]);
            flag = true;
            continue;
        }
        //相等 且范围在[A - N] or [0 - 9] 输出之后跳出
        if(flag && in[0][i] == in[1][i] && (isA_N(in[0][i]) || isNum(in[0][i]))){
            int num = in[0][i] >= 65 ? 10 + in[0][i] - 65 : in[0][i] - '0';
            printf("%02d:", num);
            break;
        }
    }
    //相等 且范围在[A - z]    输出之后结束
    for(int i = 0; i < strlen(in[2]) && i < strlen(in[3]); i++){
        if(in[2][i] == in[3][i] && isE(in[2][i])){
            printf("%02d", i);
            break;
        }
    }
    return 0;
}